using Microsoft.Xna.Framework.Content;

namespace Deferred.Library.Scene.Graphics
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content
    /// Pipeline to read the specified data type from binary .xnb format.
    /// 
    /// Unlike the other Content Pipeline support classes, this should
    /// be a part of your main game project, and not the Content Pipeline
    /// Extension Library project.
    /// </summary>
    class DeferredModelReader : ContentTypeReader<DeferredModel>
    {
        DeferredModelMeshReader meshReader = new DeferredModelMeshReader();
        protected override DeferredModel Read(ContentReader input, DeferredModel existingInstance)
        {
            if (existingInstance != null) return existingInstance;
            DeferredModel instance = new DeferredModel();

            int count = input.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                instance.Meshes.Add(input.ReadObject<DeferredModelMesh>(meshReader));
            }

            return instance;
        }
    }
}
